﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using BaseUnits;

namespace Formulas
{
    public class DispatchReport
    {
        public DataTable GetDispatchData(DateTime fromDate, DateTime toDate, IPowerPlant plant, TimeSpan span)
        {
            
            ReportData.unitDispatchDataTable table = new ReportData.unitDispatchDataTable();
            double incoming;
            double outgoing;
            DateTime nextTo = fromDate.AddDays(span.Days);
            nextTo = nextTo.AddHours(span.Hours); 
            while (nextTo < toDate)
            {
                incoming = 0;
                outgoing = 0;
                foreach (IPowerUnit pu in plant.PowerUnits)
                {
                    incoming += pu.TotalIncoming(fromDate,nextTo);
                    outgoing += pu.TotalOutgoing(fromDate,nextTo);
                }
                table.AddunitDispatchRow(nextTo, incoming, outgoing);
                fromDate = nextTo;
                nextTo = nextTo.AddDays(span.Days);
                nextTo = nextTo.AddHours(span.Hours);
            }
            return table;
        }
    }
}
